﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MashGen.Engine.Expressions.Formatter;

namespace MashGen.Engine.Expressions
{
    public abstract class AbstractExpression : IEquatable<AbstractExpression>, IComparable<AbstractExpression>
    {
        public abstract R Vist<R, P>(IExpressionVisitor<R, P> visitor, P parameter = default(P));

        public override bool Equals(object other)
        {
            var otherExpression = other as AbstractExpression;
            if (ReferenceEquals(otherExpression, null))
            {
                return false;
            }
            if (ReferenceEquals(otherExpression, this))
            {
                return true;
            }
            return Equals(otherExpression);
        }

        public abstract bool Equals(AbstractExpression other);
        public override abstract int GetHashCode();

        public int CompareTo(AbstractExpression other)
        {
            return ExpressionComparer.Instance.Compare(this, other);
        }

        public override string ToString()
        {
            return StringFormatter.Format(this, true);
        }
    }
}
